package com.tuosha.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.tuosha.dao.UsersDao;
import com.tuosha.model.UsersEntity;
import com.tuosha.service.UsersService;



@Service("usersServiceImpl")
public class UsersServiceImpl implements UsersService {
	@Autowired
	private UsersDao usersDao;
	
	@Override
	public UsersEntity queryObject(Integer id){
		return usersDao.queryObject(id);
	}
	
	@Override
	public List<UsersEntity> queryList(Map<String, Object> map){
		return usersDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return usersDao.queryTotal(map);
	}
	
	@Override
	public void save(UsersEntity users){
		Date date=new Date();
		users.setCreatedAt(date);
		users.setMoney(0.0);
		users.setMoneyAll(0.0);
		users.setLevel("用户");
		usersDao.save(users);
	}
	
	@Override
	public int update(UsersEntity users){
		Date date=new Date();
		users.setUpdatedAt(date);
		users.setLevel("用户");
		return usersDao.update(users);
	}
	
	@Override
	public int delete(Integer id){
		return usersDao.delete(id);
	}
	
	@Override
	public int deleteBatch(Integer[] ids){
		return usersDao.deleteBatch(ids);
	}

	public int delById(Integer id){

		UsersEntity member= new UsersEntity();
		member.setId(id);
		member.setStatus("0");
		return usersDao.update(member);
	}

	public int delPatch(String  tiestr){
		String[] strs = tiestr.split(",");
		if(strs!=null&&strs.length>0){
			for (String str : strs) {
				delById(Integer.parseInt(str));
			}
		}
		return 0;
	}

	public UsersEntity queryName(String name){
		return usersDao.queryName(name);
	}

	public UsersEntity queryEmailName(String name){
		return usersDao.queryEmailName(name);
	}

	public UsersEntity queryMobile(String name){
		return usersDao.queryMobile(name);
	}

	public UsersEntity queryNickName(String name){
		return usersDao.queryNickName(name);
	}

	public List<UsersEntity> queryListName(){
		return usersDao.queryListName();
	}
}
